package com.zbkj.service.service.impl.splittingAccount;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zbkj.common.model.shop.DevelopAdApply;
import com.zbkj.common.model.shop.InvitationCodeEntity;
import com.zbkj.service.dao.shop.DevelopAdApplyDao;
import com.zbkj.service.service.DevelopAdApplyService;
import com.zbkj.service.service.InvitationCodeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RequiredArgsConstructor
public class DevelopAdApplyServiceImpl extends ServiceImpl<DevelopAdApplyDao, DevelopAdApply>
        implements DevelopAdApplyService {
    @Autowired
    InvitationCodeService invitationCodeService;

    @Override
    @DS("pointarchive")
    public DevelopAdApply get(String invitationCode) {
        InvitationCodeEntity invitationCodeEntity = new InvitationCodeEntity();
        invitationCodeEntity.setXuanPinInvitationCode(invitationCode);
        InvitationCodeEntity code = invitationCodeService.getDevelopAdApply(invitationCodeEntity);
        if (code == null) {
            return null;
        }
        return this.getOne(new QueryWrapper<DevelopAdApply>()
                .lambda()
                .eq(DevelopAdApply::getUserId, code.getUserId())
                .eq(DevelopAdApply::getReviewStatus,"2")
                .last(" limit 1")
        );
    }
    @Override
    @DS("pointarchive")
    public DevelopAdApply getId(String id) {

        return this.getOne(new QueryWrapper<DevelopAdApply>()
                .lambda()
                .eq(DevelopAdApply::getUserId, id)
                .eq(DevelopAdApply::getReviewStatus,"2")
                .last(" limit 1")

        );
    }
}
